#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <regex>

class EventLoop;
class LoopThread;

class LoopThreadPool
{
private:
    int _thread_count; // 从属线程的数量
    int _next_idx;
    EventLoop *_baseloop;               // 主EventLoop，运行主线程，从属线程为0，则所有操作都在baseloop中进行
    std::vector<LoopThread *> _threads; // 保存所有的LoopThread对象
    std::vector<EventLoop *> _loops;    // 从属线程数量大于0则从_loops中进行线程EventLoop分配
public:
    LoopThreadPool();
    void SetThreadCount(int count); // 设置线程数量
    void Create();                  // 创建所有的从属线程
    EventLoop *NextLoop();
};

class HttpRequest
{
public:
    std::string _method;
    std::string _path;
    std::string _version;
    std::string _body;
    std::smatch _matches;
    std::unordered_map<std::string,std::string> _headers;
    std::unordered_map<std::string,std::string> _params;
public:
    HttpRequest();
    void ReSet();
    void SetHeader(std::string&key,std::string&val);
    void HasHeader(std::string&key);
    std::string GetHeader(std::string&key);

    void SetParam(std::string&key,std::string&val);
    void HasParam(std::string&key);
    std::string GetParam(std::string&key);

    size_t ContentLength();
    bool Close();
};


class HttpResponse
{
public:
    int _statu;
    bool _redirect_flag;
    std::string _body;
    std::string _redirect_url;
    std::unordered_map<std::string,std::string> _headers;
public:
    HttpResponse();
    void ReSet();
    void SetHeader(std::string&key,std::string&val);
    bool HasHeader(std::string&key);
    std::string GetHeader(std::string&key);

    void SetContent(std::string&body,std::string type="text/html");
    void SetRedirect(std::string*url,int statu=302);
    bool Close();
};